<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb' /></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" action="${web_domain}/merchant/seckill/list" method="get">
                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='mscc' /></label>
                        <div class="layui-input-inline">
                            <input type="text" name="seckillSession.name" placeholder="<fmt:message key='qsrmscc' />" value="${params.seckillSession.name}" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss' /></button>
                    </div>
                </form>
            </div>

        </div>

        <div class="layui-card">
            <div class="layui-field-box layui-form">

                <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i> <fmt:message key='tj' /></a>

                <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                    <ul class="layui-tab-title">
                        <li <c:if test="${params.status eq 0}">class="layui-this"</c:if>>
                            <a href="${web_domain}/merchant/seckill/list"
                               <c:if test="${params.status eq 0}">style="color: rgb(0, 150, 136)"</c:if> ><fmt:message key='qb' /></a>
                        </li>
                        <li <c:if test="${params.status eq 1}">class="layui-this"</c:if>>
                            <a href="${web_domain}/merchant/seckill/list?status=1" <c:if test="${params.status eq 1}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='dshenh' /></a>
                        </li>
                        <li <c:if test="${params.status eq 2}">class="layui-this"</c:if>>
                            <a href="${web_domain}/merchant/seckill/list?status=2" <c:if test="${params.status eq 2}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='shz' /></a>
                        </li>
                        <li <c:if test="${params.status eq 3}">class="layui-this"</c:if>>
                            <a href="${web_domain}/merchant/seckill/list?status=3" <c:if test="${params.status eq 3}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='ysj' /></a>
                        </li>
                        <li <c:if test="${params.status eq 4}">class="layui-this"</c:if>>
                            <a href="${web_domain}/merchant/seckill/list?status=4" <c:if test="${params.status eq 4}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='shbtg' /></a>
                        </li>
                        <li <c:if test="${params.status eq 5}">class="layui-this"</c:if>>
                            <a href="${web_domain}/merchant/seckill/list?status=5" <c:if test="${params.status eq 5}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='yxj' /></a>
                        </li>
                    </ul>
                </div>

                <table class="layui-table" lay-size="sm">
                    <thead>
                    <tr>
                        <th width="5%"><input id="checkboxs" type="checkbox" lay-ignore lay-skin="primary"/></th>
                        <th><fmt:message key='mscc' /></th>
                        <th><fmt:message key='mssj' /></th>
                        <th><fmt:message key='spsl' /></th>
                        <th><fmt:message key='zt' /></th>
                        <th><fmt:message key='hdzt' /></th>
                        <th><fmt:message key='cz' /></th>
                    </tr>
                    </thead>
                    <c:forEach items="${page.result}" var="item" varStatus="status">
                        <tr>
                            <td><input type="checkbox" value="${item.id}" class="feijin-check" lay-ignore lay-skin="primary"/></td>
                            <td>${item.seckillSession.name }</td>
                            <td>${item.seckillSession.seckillTime } ${item.seckillSession.seckillBeginTime } ~ ${item.seckillSession.seckillEndTime }</td>
                            <td>${item.goodsCount }</td>
                            <td>
                                <c:choose>
                                    <c:when test="${item.status eq 1}"><fmt:message key='dtj' /></c:when>
                                    <c:when test="${item.status eq 2}"><fmt:message key='shz' /></c:when>
                                    <c:when test="${item.status eq 3}"><fmt:message key='ysj' /></c:when>
                                    <c:when test="${item.status eq 4}"><fmt:message key='shbtg' /></c:when>
                                    <c:when test="${item.status eq 5}"><fmt:message key='xj' /></c:when>
                                </c:choose>
                            </td>
                            <td>
                                <c:choose>
                                    <c:when test="${item.isValidity eq 1}"><fmt:message key='wks' /></c:when>
                                    <c:when test="${item.isValidity eq 2}"><fmt:message key='hdks' /></c:when>
                                    <c:when test="${item.isValidity eq 3}"><fmt:message key='hdjs' /></c:when>
                                </c:choose>
                            </td>
                            <td>
                                <div class="layui-btn-container">

                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-detail"><fmt:message key='ck' /></a>

                                    <c:choose>
                                        <c:when test="${item.status eq 1}">
                                            <a href="javascript:void(0);" data-id="${item.id}" data-time="${item.seckillSession.seckillTime } ${item.seckillSession.seckillEndTime }" class="layui-btn layui-btn-normal layui-btn-xs feijin-apply-process"><fmt:message key='tjsh' /></a>
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-modify"><fmt:message key='bj' /></a>
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-remove"><fmt:message key='sc' /></a>
                                        </c:when>

                                        <c:when test="${item.status eq 3}">
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-soldout"><fmt:message key='xj' /></a>
                                        </c:when>

                                        <c:when test="${item.status eq 4}">
                                            <a href="javascript:void(0);" data="${item.checkNote}" class="layui-btn layui-btn-normal layui-btn-xs feijin-checkNote"><fmt:message key='ckyy' /></a>
                                            <a href="javascript:void(0);" data-id="${item.id}" data-time="${item.seckillSession.seckillTime } ${item.seckillSession.seckillEndTime }" class="layui-btn layui-btn-normal layui-btn-xs feijin-apply-process"><fmt:message key='tjsh' /></a>
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-modify"><fmt:message key='bj' /></a>
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-remove"><fmt:message key='sc' /></a>
                                        </c:when>

                                        <c:when test="${item.status eq 5}">
                                            <a href="javascript:void(0);" data-id="${item.id}" data-time="${item.seckillSession.seckillTime } ${item.seckillSession.seckillEndTime }" class="layui-btn layui-btn-normal layui-btn-xs feijin-apply-process"><fmt:message key='tjsh' /></a>
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-modify"><fmt:message key='bj' /></a>
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-remove"><fmt:message key='sc' /></a>
                                        </c:when>

                                    </c:choose>


                                </div>
                            </td>
                        </tr>
                    </c:forEach>
                </table>
                <jsp:include page="/commons/page.jsp" flush="true"/>
            </div>
        </div>

    </div>

    <script>

        $(function () {

            //全选反选
            $("#checkboxs").click(function () {
                if (this.checked) {
                    $(".feijin-check:checkbox").prop("checked", true);
                } else {
                    $(".feijin-check:checkbox").prop("checked", false);
                }
            });


            layui.use(['form', 'laydate'], function () {

                var form = layui.form;
                var laydate = layui.laydate;

            });

            //查看详情
            $(".feijin-detail").click(function () {

                var id = $(this).attr("data-id");

                layer.open({
                    type: 2
                    , title: '<fmt:message key='ckxq' />'
                    , content: '${web_domain}/merchant/seckill/' + id + '/detail'
                    , maxmin: true
                    , area: ['97%', '97%']
                    , btn: ['<fmt:message key='fh' />']
                });
            });

            //申请审核秒杀活动
            $(".feijin-apply-process").click(function () {
                var id = $(this).attr("data-id");
                var time = $(this).attr("data-time");

                var endTime = new Date(Date.parse(time.replace(/-/g, "/")));

                var curDate = new Date();

                if (endTime < curDate) {
                    layer.msg("<fmt:message key='hdygjssj' />");
                    return false;
                }

                layer.confirm("<fmt:message key='qrshmshd' />", function () {
                    feijin.put({
                        url: "${web_domain}/merchant/seckill/applyProcess",
                        data: {id: id}
                    });
                });
            });

            //下架商品
            $(".feijin-soldout").click(function () {
                var id = $(this).attr("data-id");
                layer.confirm("<fmt:message key='qrxjgspm' />", function () {
                    feijin.put({
                        url: "${web_domain}/merchant/seckill/soldout",
                        data: {id: id}
                    });
                });
            });

            //删除秒杀活动
            $(".feijin-remove").click(function () {
                var id = $(this).attr("data-id");
                layer.confirm("<fmt:message key='qrscmshd' />", function () {
                    feijin.delete({
                        url: "${web_domain}/merchant/seckill/remove",
                        data: {id: id}
                    });
                });
            });

            $(".feijin-checkNote").click(function () {
                var checkNote = $(this).attr("data");
                layui.use('layer', function () {
                    layer.msg(checkNote);
                });
            });

            //添加秒杀活动
            $("#add").click(function () {
                layer.open({
                    type: 2
                    , title: '<fmt:message key='tjmshd' />'
                    , content: '${web_domain}/merchant/seckill/create'
                    , maxmin: true
                    , area: ['97%', '97%']
                    , btn: ['<fmt:message key='bc' />', '<fmt:message key='qx' />']
                    , yes: function (index, layero) {
                        var submit = layero.find('iframe').contents().find("#submit");
                        submit.click();
                    }
                });
            });

            //编辑
            $(".feijin-modify").click(function () {

                var id = $(this).attr("data-id");

                layer.open({
                    type: 2
                    , title: '<fmt:message key='bjmshd' />'
                    , content: '${web_domain}/merchant/seckill/' + id + '/modify'
                    , maxmin: true
                    , area: ['97%', '97%']
                    , btn: ['<fmt:message key='bc' />', '<fmt:message key='qx' />']
                    , yes: function (index, layero) {
                        var submit = layero.find('iframe').contents().find("#submit");
                        submit.click();
                    }
                });
            });

        });
    </script>
</body>
</fmt:bundle>
</html>
